package interceptor;

import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;

import handler.MerchantWebSocketHandler;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


public class MerchantHandshakeInterceptor implements HandshakeInterceptor {
	
	@Resource(name="merchantWebSocketHandler")
	private MerchantWebSocketHandler handler;

    @Override
    public boolean beforeHandshake(ServerHttpRequest request,
                                   ServerHttpResponse response, WebSocketHandler wsHandler,
                                   Map<String, Object> attributes) throws Exception {
    	ServletServerHttpRequest request2 = (ServletServerHttpRequest)request;
    	HttpSession session = request2.getServletRequest().getSession();
    	if (session.getAttribute("user")!=null) {
    		attributes.put("user", session.getAttribute("user"));
		}
    	
        return true;
    }

    @Override
    public void afterHandshake(ServerHttpRequest request,
                               ServerHttpResponse response, WebSocketHandler wsHandler,
                               Exception exception) {


    }

}